<?php

namespace LowCode\Naive;

use LowCode\Naive;
use LowCode\Support\JsExp;

/**
 * InfiniteScroll
 * @method static InfiniteScroll make(mixed $children = null) InfiniteScroll组件
 */
class InfiniteScroll extends Naive
{

    /**
     * @param mixed|null $children
     */
    public function __construct(mixed $children = null)
    {
        parent::__construct();
        $this->children($children);
    }

    /**
     * 触发加载的距离阈值
     * @param int|JsExp $value
     * @return $this
     */
    public function distance(int|JsExp $value = 0): static
    {
        return $this->prop('distance', $value);
    }

    /**
     * 触发加载的距离阈值
     * @param array|JsExp|Scrollbar $value
     * @return $this
     */
    public function scrollbarProps(array|JsExp|Scrollbar $value = []): static
    {
        if ($value instanceof Scrollbar){
            $value = $value->props??[];
        }
        return $this->prop('scrollbar-props', $value);
    }

    /**
     * onLoad 滚动到底部时的回调函数
     * @param string $value 函数 () => Promise<void> | void
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onLoad(string $value = "()=>{ }", string $id = null, array $modifiers = []): static
    {
        return $this->event("load",jsFn($value, $id), $modifiers);
    }
}
